package com.shanshan.wheel.rpc.common.loadbalance.loadbalancer;

import com.shanshan.wheel.rpc.common.loadbalance.AbstractLoadBalance;
import lombok.extern.slf4j.Slf4j;

import java.net.UnknownHostException;
import java.util.List;
import java.util.Random;

/**
 * @Description 随机均衡
 * @ClassName RandomLoadBalance
 * @Author 山山大魔王
 * @Date 2022/9/4 11:46
 * @Version 1.0
 */
@Slf4j
public class RandomLoadBalance extends AbstractLoadBalance {
    @Override
    protected String doSelect(List<String> serviceAddress, String rpcServiceName) throws UnknownHostException {
        Random random = new Random();
        return serviceAddress.get(random.nextInt(serviceAddress.size()));
    }
}
